package com.taiyi.renaissancemall.ui.main.goodsdetail.commentList;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.taiyi.renaissancemall.R;
import com.taiyi.renaissancemall.Utils.RegexUtil;
import com.taiyi.renaissancemall.adapter.AdapterManager;
import com.taiyi.renaissancemall.adapter.baseadapter.CommonAdapter;
import com.taiyi.renaissancemall.bean.AllCommentListBean;

import java.util.ArrayList;
import java.util.List;

public class CommentListAdapter extends BaseQuickAdapter<AllCommentListBean.CommentlistBean, BaseViewHolder> {
    public CommentListAdapter(int layoutResId, @Nullable List<AllCommentListBean.CommentlistBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AllCommentListBean.CommentlistBean item) {
        helper.setText(R.id.levelTv, item.levelname);
        helper.setText(R.id.dateTv, item.createtime);
        helper.setText(R.id.commentsTv, item.evaluate_ramrk);
        String tel = RegexUtil.phoneNoHide(item.tel);
        helper.setText(R.id.nameTv, tel);
        String imgurl = item.evimgurl;
        List<String> imgList = new ArrayList<>();
        if (imgurl != null) {
            if (imgurl.contains(",")) {
                String[] split = imgurl.split(",");
                for (String in : split) {
                    imgList.add(in);
                }
            } else {
                imgList.add(imgurl);
            }
        }
        RecyclerView recyclerView = helper.getView(R.id.commentsRecyclerView);
        GridLayoutManager layoutManager = new GridLayoutManager(mContext, 3);
        CommonAdapter imageAdapter = AdapterManager.getCommentListImageAdapter(mContext, imgList);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(imageAdapter);
        imageAdapter.notifyDataSetChanged();
    }
}
